﻿@{
    var pageindex = Convert.ToInt32(ViewBag.PageIndex);
    var pagecount = Convert.ToInt32(ViewBag.PageCount);
}
<ul class="am-pagination">
    @{
        var pagestart = pageindex - 2 > 0 ? pageindex - 2 : 1;
        var pageend = pagestart + 5 >= pagecount ? pagecount : pagestart + 5;
    }
    <li class="prev previous_page @(pageindex == 1 ? "disabled" : "")">
        <a href="@(pageindex==1?"#":Url.Action("Index","Article",new { category=@ViewBag.Category,page=pageindex-1}))">&#8592; 上一页</a>
    </li>
    <li @(pageindex == 1 ? "class=current-page" : "")><a rel="start" href="@Url.Action("Index","Article",new { category=ViewBag.Category,page=1})">1</a></li>
    @if (pagestart > 1)
    {
        <li class="disabled"><a href="#">&hellip;</a></li>
    }
    @for (int i = pagestart; i < pageend; i++)
    {
        if (i > 1)
        {
            <li @(pageindex == i ? "class=current-page" : "")><a rel="next" href="@Url.Action("Index","Article",new { category=ViewBag.Category,page=i})">@i</a></li>
        }
    }
    @if (pageend < pagecount)
    {
        <li class="disabled"><a href="#">&hellip;</a></li>
    }
    @if (pagecount > 1)
    {
        <li @(pageindex == pagecount ? "class=current-page" : "")><a rel="end" href="@Url.Action("Index","Article",new { category=ViewBag.Category,page=pagecount})">@pagecount</a></li>
    }
    <li class="next next_page @(pageindex==pagecount?"disabled":"")">
        <a rel="next" href="@(pageindex==pagecount?"#":Url.Action("Index","Article",new { category=@ViewBag.Category,page=pageindex+1}))">下一页 &#8594;</a>
    </li>
</ul>